package com.group.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.finance.entity.Deal;
import com.group.finance.dao.DealMapper;
import com.group.finance.service.IDealService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zgc
 * @since 2022-06-07
 */
@Service
public class DealServiceImpl extends ServiceImpl<DealMapper, Deal> implements IDealService {

    @Resource
    private DealMapper dealMapper;

    @Override
    public List<Deal> findSucceedDeal(int current, int size, String status) {

        QueryWrapper<Deal> wrapper = new QueryWrapper();

        //设置查询条件，eq是等于，查询status字段等于传入的status的数据
        wrapper.eq("status", status);

        Page<Deal> page = new Page<>(current,size);

        IPage<Deal> dealEntityIPage = dealMapper.selectPage(page, wrapper);


        System.out.println("总页数"+dealEntityIPage.getPages());
        System.out.println("总记录数"+dealEntityIPage.getTotal());

        List<Deal> dealEntityList = dealEntityIPage.getRecords();

        return dealEntityList;
    }

    @Override
    public Integer addDeal(Deal deal) {
        int insert = dealMapper.insert(deal);
        Integer integer = insert;
        return integer;
    }
}
